<%@ page import="java.util.Date" %>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core"%>
<%@taglib uri="http://www.springframework.org/tags/form" prefix="form"%>
<%@ taglib prefix="fmt" uri="http://java.sun.com/jsp/jstl/fmt"%>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core"%>

<script src="<c:url value="/resources/js/jquery.tablesorter.min.js"/>"></script>

<div class="row full-width">
	<div class="columns">
		<div
			class="large-12 medium-14 small-16 large-centered medium-centered small-centered columns">
			<!--content-->
			<br>
			<div class="row collapse">
				<div class="large-16 small-16 background-secondary columns">
					<div>
						<br>
						<div class="row" align="center">
							<div class="columns">
								<span class="subscribed-number" id="currencyCode">${currencyName}</span><span class="subscribed"> Rates Table</span>
								<div>
									<span class="link-xrates">Based on </span><a href="https://finance.yahoo.com/currency-converter" target="_blank" class="link-xrates">Yahoo Finance</a>
									<jsp:useBean id="now" class="java.util.Date"/>
									<fmt:formatDate var="time" value="${now}" pattern="HHmm"/>
									<c:set var="yesterday" value="<%=new Date(new Date().getTime() - 60*60*24*1000)%>"/>
									
									<c:choose>
										<c:when test="${time lt '1400'}">
											<span class="link-xrates"><fmt:formatDate value="${yesterday}" pattern="MMM dd, yyyy" /> 14:00</span>
										</c:when>
										<c:otherwise>
											<span class="link-xrates"><fmt:formatDate value="${now}" pattern="MMM dd, yyyy" /> 14:00</span>
										</c:otherwise>
									</c:choose>
								</div>
							</div>
						</div>
						<br>
						<div class="row" align="center">
							<div class="columns">
								<table id="keywords">
									<thead>
										<tr>
											<th class="headerSortDown"><span>Code</span></th>
											<th><span>Name</span></th>
											<th>
												<span style="float: right">1.00 <a style="color: #3EC647;">${currencyCode}</a>
												</span>
											</th>
										</tr>
									</thead>
									<tbody>
										<c:forEach var="exchangeRate" items="${ratesList}" >
										<tr>
											<td>${exchangeRate.code}</td>
											<td>${exchangeRate.name}</td>
											<td><span hidden>${exchangeRate.rate}</span><span style="float: right; color: #2672A1; font-weight: bold;">${exchangeRate.rateStr}</span></td>
										</tr>
										</c:forEach>
								</table>
							</div>
						</div>
						<br>
					</div>
				</div>
			</div>
		</div>
	</div>
</div>

<script type="text/javascript">
$(function(){
  $('#keywords').tablesorter(); 
});
</script>